/**   
 * Copyright © 2017 Fan_繁. All rights reserved.
 * 
 * @Title: GlobalException.java 
 * @Prject: anger
 * @Package: com.hzt.anger.config 
 * @Description: TODO
 * @author: ChuanHui   
 * @date: 2017年8月6日 下午3:22:04 
 * @version: V1.0   
 */
package com.hzt.anger.config;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

/**
 * @ClassName: GlobalException
 * @Description: 定义异常记录信息
 * @author: ChuanHui
 * @date: 2017年8月6日 下午3:22:04
 */
@Component
public class GlobalException implements HandlerExceptionResolver {

	private Logger logger = LoggerFactory.getLogger(this.getClass());

	/*
	 * (non Javadoc)
	 * 
	 * @Title: resolveException
	 * 
	 * @Description: TODO
	 * 
	 * @param request
	 * 
	 * @param response
	 * 
	 * @param handler
	 * 
	 * @param ex
	 * 
	 * @return
	 * 
	 * @see
	 * org.springframework.web.servlet.HandlerExceptionResolver#resolveException(
	 * javax.servlet.http.HttpServletRequest,
	 * javax.servlet.http.HttpServletResponse, java.lang.Object,
	 * java.lang.Exception)
	 */
	@Override
	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
			Exception ex) {
		Map<String, Object> model = new ConcurrentHashMap<String, Object>();
		model.put("ex", ex);
		logger.info("==========发生了异常：");
		logger.info("==========异常类型：" + ex.getClass().getSimpleName());
		logger.info("==========异常描述：" + ex.getMessage());
		logger.info("==========异常原因：" + ex.getCause());
		return new ModelAndView("error", model);
	}

}
